<?php

class Core_Backend_Component_Website_View_Template_Create extends Core_Backend_Share_View_Form {

    public function __construct() {
        parent::__construct();
        $this->setTemplatePath('edit');
    }

    protected function buildNavigation($navigation) {
        $navigation->addLabel($this->__f('website.title.template_create', $this->getArea()->getName()));
        parent::buildNavigation($navigation);
    }

    protected function buildToolbar($toolbar) {
    	$group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('website/template/index'), $this->__('share.button.back'));
        $group = $toolbar->createGroup('save');
        $group->addButton($this->__('share.button.apply'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(NULL, 'apply')."')");
        $group->addButton($this->__('share.button.save'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(NULL, 'save')."')");
        parent::buildToolBar($toolbar);
    }

    public function buildForm($form) {
        $entity = $this->getModel();
        $form->setAction($this->getUrl())
                ->setId('template_form')
                ->addHiddenField('area_id', 'template[area_id]', $this->getArea()->getId())
                ->addHiddenField('id', 'template[id]')
                ->addTextboxField($this->__('share.label.name'), 'name', 'template[name]', TRUE)
                ->addRequiredRule()->getForm()
                ->addTextboxField($this->__('share.label.theme'), 'theme', 'template[theme]', TRUE)
                ->addRequiredRule()->addCharacterRule()->getForm()
                ->addTextboxField($this->__('share.label.skin'), 'skin', 'template[skin]', TRUE)
                ->addRequiredRule()->addCharacterRule()->getForm()
                ->addTextboxField($this->__('global.label.layout'), 'layout', 'template[layout]', TRUE)
                ->addRequiredRule()->addCharacterRule()->getForm()
                ->addTextboxField($this->__('global.label.position'), 'position', 'template[position]', TRUE)
                ->addRequiredRule();
        if (!is_null($entity)) {
            $form->bindData($entity->getAllData());
        }
        parent::buildForm($form);
    }

}


